<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .shang {
            width: 500px;
            height: 500px;
            background-color: aqua;
            margin: auto;
        }

        .p2 {
            width: 263px;
            height: 36px;
        }

        button {
            width: 70px;
            height: 40px;
        }
    </style>
</head>

<body>
    <div class="shang">
        <input type="text" class="p2"><button onclick="ti()">提交</button>
        <ul>
        </ul>
    </div>
    <script>
        var arr = [{
            id: 1,
            name: '玩游戏'
        }, {
            id: 2,
            name: '敲代码'
        }, {
            id: 3,
            name: '睡觉'
        }, {
            id: 4,
            name: '吃饭'
        },]
        // 获取dom
        var ul = document.querySelector('ul')
        // 渲染
        function xr() {
            ul.innerHTML=''
            arr.forEach(item => {
                ul.innerHTML += `
                    <input type="checkbox"> 
                    <span>${item.name}</span>
                    <input type="checkbox"><br>`
            })
        }
        xr()
        // 添加
        var inp1 = document.querySelectorAll('input')[0]
        function ti() { 
            arr.push({
                name:inp1.value
            })
            xr()
        }    
    </script>
</body>
</html>